package com.hemaapp.yjnh.view;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 *
 */
public class SoundProgressBar extends ImageView {
	private Thread mThread;
	private Runnable mRunnable;
	private boolean isRun;
	Handler mHandler;

	public SoundProgressBar(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		set();
	}

	public SoundProgressBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		set();
	}

	public SoundProgressBar(Context context) {
		super(context);
		set();
	}

	void set() {
		mRunnable = new Runnable() {
			private int i = 1;

			@Override
			public void run() {
				while (isRun) {
					Message mess = mHandler.obtainMessage();
					mess.what = i;
					mHandler.sendMessage(mess);
					if (i < 3)
						i++;
					else
						i = 1;
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						// ignore
					}
				}
				i = 1;
				Message mess = mHandler.obtainMessage();
				mess.what = 3;
				mHandler.sendMessage(mess);
			}
		};
	}

	public void start() {
		isRun = true;
		mThread = new Thread(mRunnable);
		mThread.start();
	}

	public void stop() {
		isRun = false;
	}
}
